home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / sbin / gconf-schemas < prev    next >
Text File  |  2009-10-07  |  3KB  |  90 lines

  1. #! /usr/bin/python
  2. #
  3. # copyright (c) 2006 Josselin Mouette <joss@debian.org>
  4. # Licensed under the GNU Lesser General Public License, version 2.1
  5. # See COPYING for details
  6.  
  7. from optparse import OptionParser
  8. import sys,os,os.path,shutil,tempfile
  9.  
  10. parser = OptionParser(usage="usage: %prog --[un]register file1.schemas [file2.schemas [...]]")
  11.  
  12. parser.add_option("--register", action="store_true", dest="register",
  13.                   help="register schemas to the GConf database",
  14.                   default=None)
  15. parser.add_option("--unregister", action="store_false", dest="register",
  16.                   help="unregister schemas from the GConf database",
  17.                   default=None)
  18. parser.add_option("--register-all", action="store_true", dest="register_all",
  19.                    help="clean up the GConf database and register all schemas again",
  20.                    default=False)
  21. parser.add_option("--no-signal", action="store_false", default=True, dest="signal",
  22.                   help="do not send SIGHUP the running gconfd-2 processes")
  23. (options, args) = parser.parse_args()
  24.  
  25. if options.register==None and not options.register_all:
  26.   parser.error("You need to specify --register or --unregister.")
  27.  
  28. schema_location="/usr/share/gconf/schemas"
  29. defaults_dest="/var/lib/gconf/defaults"
  30.  
  31. schemas = [ ]
  32. if options.register_all:
  33.   for f in os.listdir(schema_location):
  34.     if f.endswith(".schemas"):
  35.       schemas.append(os.path.join(schema_location,f))
  36. else:
  37.   for schema in args:
  38.     if not os.path.isabs(schema):
  39.       schema=os.path.join(schema_location,schema)
  40.     if os.path.isfile(schema):
  41.       schemas.append(schema)
  42.     else:
  43.       sys.stderr.write('Warning: %s could not be found.\n'%schema)
  44.  
  45. if len(schemas)<1:
  46.   parser.error("You need at least a file to (un)register.")
  47.  
  48. if os.geteuid():
  49.   parser.error("You must be root to launch this program.")
  50.  
  51. if options.register_all:
  52.   options.register=True
  53.   for f in os.listdir(defaults_dest):
  54.     os.remove(os.path.join(defaults_dest,f))
  55.   open(os.path.join(defaults_dest,"%gconf-tree.xml"),"w").close()
  56.  
  57. tmp_home=tempfile.mkdtemp(prefix='gconf-')
  58. env={'HOME': tmp_home,
  59.      'GCONF_CONFIG_SOURCE': 'xml:readwrite:'+defaults_dest}
  60. if options.register:
  61.   arg='--makefile-install-rule'
  62. else:
  63.   arg='--makefile-uninstall-rule'
  64.  
  65. fd = os.open("/dev/null",os.O_WRONLY)
  66. save_stdout=os.dup(1)
  67. os.dup2(fd,1)
  68. os.close(fd)
  69. res=os.spawnvpe(os.P_WAIT,'gconftool-2',['gconftool-2',arg]+schemas,env)
  70. os.dup2(save_stdout,1)
  71. os.close(save_stdout)
  72.  
  73. shutil.rmtree(tmp_home)
  74.  
  75. if(res):
  76.   sys.exit(res)
  77.  
  78. if options.register and options.signal:
  79.   # tell running processes to re-read the GConf database
  80.   import signal
  81.   try:
  82.     pids=os.popen('pidof gconfd-2').readlines()[0].split()
  83.     for pid in pids:
  84.       try:
  85.         os.kill(int(pid),signal.SIGHUP)
  86.       except OSError:
  87.         pass
  88.   except IndexError:
  89.     pass
  90.